<template>
  <div id="app">
    <global-header :user="currentUser"></global-header>
    <Loading v-if="isLoading" text="拼命加载中" background="rgba(0, 0, 0, 0.8)"></Loading>
    <div class="container">
      <router-view></router-view>
      <Waline :serverURL="serverURL" :path="path" :darkmode="darkmode" />
    </div>
    <footer class="text-center py-4 text-secondary bg-light mt-6 footer">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">@ 2022知乎专栏</li>
          <li class="list-inline-item">课程</li>
          <li class="list-inline-item">文档</li>
          <li class="list-inline-item">联系</li>
          <li class="list-inline-item">更多</li>
        </ul>
      </small>
    </footer>
  </div>
</template>

<script>
import { defineComponent, reactive, ref, computed, onMounted, watch } from 'vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import GlobalHeader from './components/GlobalHeader.vue'
import { UserProps } from '@/hooks/testData'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import { Waline } from '@waline/client/dist/component'
import '@waline/client/dist/waline.css'
import Loading from '@/components/Loader.vue'
import Message from '@/components/Message.vue'
import createMessage from '@/hooks/createMessage'
export default defineComponent({
  name: "App",
  components: {
    GlobalHeader,
    Waline,
    Loading
  },
  created() {
    // this.loadUser()
  },
  methods: {
    async loadUser() {
      const store = useStore()
      try {
        await store.commit('TOKEN')
        await store.dispatch('getUserInfo')
      } catch (error) {
        // alert(error)
      }
    }
  },
  setup () {
    const store = useStore()
    const currentUser = computed(() => store.state.user)
    const serverURL = 'https://waline-e6tbjxdrq-mathieulin.vercel.app'
    const path = computed(() => useRoute().path)
    const isLoading = computed(() => store.state.loading)
    const darkmode = ref(false)
    const error = computed(() => store.state.error)
    watch(() => error.value.state, () => {
      const { state, message } = error.value
      if (state && message) {
        createMessage(message, 'error')
      }
    })
    return {
      currentUser: currentUser,
      serverURL,
      path,
      darkmode,
      isLoading,
      error
    }
  }
})
</script>

<style scoped lang="less">
@import url("//unpkg.com/element-ui@2.15.6/lib/theme-chalk/index.css");
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  position: absolute;
  text-align: center;
  width: 100%;
  height: 100%;
  min-width: 1250px;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}

.footer{
  ul {
    li {
      list-style: none;
      cursor: pointer;
    }
  }
}
</style>
